/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.maternity.classes.dao;

import br.com.maternity.classes.entity.Clinica;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Gattini
 */
public class ClinicaDAO extends GenericDAO<Clinica> {
        private static Clinica instance = new Clinica();

    public ClinicaDAO() {
        super(instance);
    }

    @Override
    public List<GenericDAOField> listFields() {
        List l = new ArrayList<GenericDAOField>();

        l.add(new GenericDAOField(
                "CNS", "setCns", "getCns", Integer.class, true, GenericDAOFieldPrimaryKey.NOTHING));
        l.add(new GenericDAOField(
                "Descricao", "setDescricao", "getDescricao", String.class));

        return l;
    }

    @Override
    public String tableName() {
        return "Clinica";
    }
    
    public List<Clinica> selectAll(){
        return super.selectList("SELECT * FROM " + tableName());
    }

    public Clinica getByCns(Integer cns) {
        try {
            String query = "SELECT * FROM " + tableName() + " WHERE CNS = ?";
            PreparedStatement ps = super.getPreparedStatement(query);
            ps.setInt(1, cns);
            return select(ps);
        } catch (Exception ex) {
            return null;
        }
    }
}
